﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;

namespace LenderClearingHouse.Helpers
{
    public class DateValidator
    {
        public static List<object> ValidateCalendarDate(string txtFromDate, string txtToDate, Nullable<DateTime> calendarFromDate, Nullable<DateTime> calendarToDate)
        {
            try
            {
                calendarFromDate = DateTime.Parse(txtFromDate);
            }
            catch (Exception ex)
            {
                calendarFromDate = DateTime.Now.AddYears(-1);
                txtFromDate = calendarFromDate.Value.Month.ToString() + "/" + calendarFromDate.Value.Day.ToString() + "/" + calendarFromDate.Value.Year.ToString();
            }

            try
            {
                calendarToDate = DateTime.Parse(txtToDate);
            }
            catch (Exception ex)
            {
                calendarToDate = DateTime.Now;
                txtToDate = calendarToDate.Value.Month.ToString() + "/" + calendarToDate.Value.Day.ToString() + "/" + calendarToDate.Value.Year.ToString();
            }

            var listDate = new List<object>();
            listDate.Add(txtFromDate);
            listDate.Add(txtToDate);
            listDate.Add(calendarFromDate);
            listDate.Add(calendarToDate);

            return listDate;
        }
    }
}